Overview
Duet provides two execution environments: the shared terminal workspace and isolated Cloudflare Sandboxes. Sandboxes allow you to run commands in a secure, ephemeral container without affecting your main workspace.Why sandboxes?
Sandboxes are useful for:Testing dangerous commands
Try commands like
rm -rf without risking your workspaceAI command execution
Let the AI run commands in isolation and show you the output
Quick experiments
Test shell scripts or one-liners without cluttering your workspace
Parallel execution
Run commands concurrently while continuing work in the main terminal
Running commands in a sandbox
PressCtrl+R to execute a command in the sandbox:
1
Open sandbox input
Press
Ctrl+R in the terminal. You’ll see:2
Enter your command
Type any shell command:
3
View the result
A toast notification appears with the output:Press
Esc to cancel without executing.Sandbox execution requires a Cloudflare Worker URL, just like the AI assistant:
Architecture
Sandboxes are powered by Cloudflare’s Browser Rendering service:Per-room sandboxes
Each room gets its own persistent sandbox instance:- Files created in the sandbox persist across commands (within the same session)
- Each room’s sandbox is completely isolated from others
- When the room ends, the sandbox is destroyed
- Lifecycle
- Isolation
Command execution flow
1
Client sends request
The Go client makes an HTTP POST to the Worker:
2
Worker validates input
The Worker uses Zod for schema validation:
3
Sandbox executes command
Cloudflare runs the command in an isolated container and captures stdout/stderr.
4
Result returned to client
Response format
Sandbox execution returns both stdout and stderr:AI integration
The AI assistant automatically uses sandboxes when it includes<run> tags:
Example
When you ask the AI:API endpoint
endpoint
Execute a command in the room’s sandboxRequest body:Success response:Error response:
Cleanup
When a room ends, the sandbox is automatically destroyed:- The last participant leaves the room
- The Go server calls
DELETE /api/rooms/:roomId - The Worker destroys the sandbox and clears AI state
Cleanup is best-effort. If the Worker is unreachable, Cloudflare will eventually garbage-collect idle sandboxes.
Limitations
No long-running processes
No long-running processes
Sandboxes are designed for short commands. Long-running processes may be terminated:
Limited filesystem
Limited filesystem
Sandboxes have a restricted filesystem with minimal tools. Advanced utilities may not be available.
No network access
No network access
Sandboxes cannot make outbound network requests:
Resource limits
Resource limits
CPU and memory are constrained. Intensive operations may be throttled or killed.
Error handling
- Command not found
- Execution timeout
- Validation error
Comparison: Sandbox vs Terminal
Best practices
Use for experiments
Test unfamiliar commands in the sandbox before running in the terminal
Check output length
Sandbox output is truncated to 500 characters. For long output, use the terminal.
Don't rely on state
Sandboxes are destroyed when the room ends. Use the terminal for persistent work.
Verify AI commands
Always review AI-generated commands before manually running them in your terminal.
Next steps
AI assistant
Learn how the AI uses sandboxes for command execution
Deploy a Worker
Set up Cloudflare Worker and Sandbox bindings